package com.example.hospitalmanagement.activity

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.CheckBox
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.adapter.RegisterActivityAdapter
import com.example.hospitalmanagement.bean.DiagnosisAndTreatmentItem
import com.example.hospitalmanagement.utils.AutoHideBottomUIDialog

/**
 * 预约挂号Activity
 */
class RegisterActivity : AppCompatActivity() {
    private lateinit var registerDiaLog: AutoHideBottomUIDialog
    private var dialogHeight = 460F
    private lateinit var adapter: RegisterActivityAdapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)
        initView()
    }

    /**
     * 负责页面显示以及跳转(预约挂号+取号支付+预约记录)
     */
    @SuppressLint("ResourceAsColor")
    private fun initView() {
        val registerItems: RecyclerView = findViewById(R.id.register_items)
        registerItems.layoutManager = GridLayoutManager(this, 2)
        val dataList: MutableList<DiagnosisAndTreatmentItem> = mutableListOf(
            DiagnosisAndTreatmentItem(
                R.mipmap.price_announcement,
                "预约挂号"
            ), DiagnosisAndTreatmentItem(
                R.mipmap.price_announcement,
                "取号支付"
            ), DiagnosisAndTreatmentItem(
                R.mipmap.price_announcement,
                "预约记录"
            )
        )
        adapter = RegisterActivityAdapter(this)
        adapter.dataList = dataList
        registerItems.adapter = adapter

        adapter.setListener {
            when (it) {
                0 -> {
                    registerDiaLog = AutoHideBottomUIDialog(this)
                    registerDiaLog.setContentView(R.layout.reservation_notice_dialog)
                    registerDiaLog.setDialogHeight(dialogHeight)
                    val dialogCheckBox: CheckBox = registerDiaLog.findViewById(R.id.dialog_checkbox)
                    val diaLogButton: Button = registerDiaLog.findViewById(R.id.dialog_button)
                    diaLogButton.setBackgroundColor(this.getColor(R.color.dialog_button_color_unchecked))
                    diaLogButton.isEnabled = false
                    dialogCheckBox.setOnClickListener {
                        if (dialogCheckBox.isChecked) {
                            diaLogButton.setBackgroundColor(this.getColor(R.color.dialog_button_color))
                            diaLogButton.isEnabled = true
                        } else {
                            diaLogButton.setBackgroundColor(this.getColor(R.color.dialog_button_color_unchecked))
                            diaLogButton.isEnabled = false
                        }
                    }

                    diaLogButton.setOnClickListener {
                        val intent = Intent(this@RegisterActivity, DepartmentActivity::class.java)
                        intent.putExtra("state",0)
                        startActivity(intent)
                    }

                    registerDiaLog.show()
                }
                2 -> { startActivity(Intent(this@RegisterActivity, ReservationRecordActivity::class.java)) }
            }
        }
    }
}